package br.com.android.financas.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import br.com.android.financas.model.Cores;

public class CoresAdapter extends ArrayAdapter<Cores> {

	private Activity activity;

	public CoresAdapter(Context context, int textViewResourceId,Cores[] objects) {
		super(context, textViewResourceId, objects);
		this.activity=(Activity) context;
	}

	@Override
	public View getDropDownView(int position, View convertView,
			ViewGroup parent) {
		// TODO Auto-generated method stub
		return getCustomView(position, convertView, parent);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return getCustomView(position, convertView, parent);
	}

	public View getCustomView(int position, View convertView,
			ViewGroup parent) {
		// TODO Auto-generated method stub
		// return super.getView(position, convertView, parent);

		LayoutInflater inflater = activity.getLayoutInflater();
		View row = inflater.inflate(android.R.layout.simple_spinner_item, parent, false);
		TextView item = (TextView) row.findViewById(android.R.id.text1);

		item.setBackgroundColor(Color.parseColor( ((Cores) Cores.values()[position]).getCor()) );

		return row;
	}
}